using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using SFS.SampleApp.Web.Mvc.Resources;
using System.Runtime.Serialization;
using SFSdotNet.Framework.Web.Mvc.Models;
using SFSdotNet.Framework.Web.Mvc.Extensions;
using BO = SFS.SampleApp.BusinessObjects;
using System.Web.Mvc;
using SFSdotNet.Framework.Web.Mvc.Validation;
using SFSdotNet.Framework.Web.Mvc.Models;
using SFSdotNet.Framework.Web.Mvc.Resources;
using SFSdotNet.Framework.Entities.Metadata;


namespace SFS.SampleApp.Web.Mvc.Models.Products 
{
	public partial class ProductModel: ModelBase{
		public ProductModel()
        {
		}
		public override string Id
        {
            get
            {
                return this.ProductID.ToString();
            }
        }
			
			
        public override string ToString()
        {
		
            return this.Name.ToString();
		
        }    
			
	
		[SystemProperty()]		
		public Int32? ProductID{ get; set; }
		
	
[Exportable()]
	
	    [Required(AllowEmptyStrings=false, ErrorMessageResourceName="VAL_NAME_REQUIRED", ErrorMessageResourceType=typeof(ProductResources))]
		
	[RelationFilterable()]
	[LocalizedDisplayName("NAME", NameResourceType=typeof(ProductResources))]
	public String   Name { get; set; }
		
		
	
[Exportable()]
	
	    [Required(AllowEmptyStrings=false, ErrorMessageResourceName="VAL_PRODUCTNUMBER_REQUIRED", ErrorMessageResourceType=typeof(ProductResources))]
		
	[RelationFilterable()]
	[LocalizedDisplayName("PRODUCTNUMBER", NameResourceType=typeof(ProductResources))]
	public String   ProductNumber { get; set; }
		
		
	
[Exportable()]
		
	[RelationFilterable()]
	[LocalizedDisplayName("COLOR", NameResourceType=typeof(ProductResources))]
	public String   Color { get; set; }
		
		
	
[Exportable()]
	
	    [Required(AllowEmptyStrings=false, ErrorMessageResourceName="VAL_STANDARDCOST_REQUIRED", ErrorMessageResourceType=typeof(ProductResources))]
		
	[RelationFilterable()]
	[LocalizedDisplayName("STANDARDCOST", NameResourceType=typeof(ProductResources))]
	public Decimal   StandardCost { get; set; }
    public string StandardCostText {
        get {
				return StandardCost.ToString();
				
        }
        
    }

		
		
	
[Exportable()]
	
	    [Required(AllowEmptyStrings=false, ErrorMessageResourceName="VAL_LISTPRICE_REQUIRED", ErrorMessageResourceType=typeof(ProductResources))]
		
	[RelationFilterable()]
	[LocalizedDisplayName("LISTPRICE", NameResourceType=typeof(ProductResources))]
	public Decimal   ListPrice { get; set; }
    public string ListPriceText {
        get {
				return ListPrice.ToString();
				
        }
        
    }

		
		
	
[Exportable()]
		
	[RelationFilterable()]
	[LocalizedDisplayName("SIZE", NameResourceType=typeof(ProductResources))]
	public String   Size { get; set; }
		
		
	
[Exportable()]
		
	[RelationFilterable()]
	[LocalizedDisplayName("WEIGHT", NameResourceType=typeof(ProductResources))]
	public Decimal  ? Weight { get; set; }
    public string WeightText {
        get {
	
            if (Weight != null)
				return Weight.ToString();
				
            else
                return String.Empty;
				
        }
        
    }

		
		
	
[Exportable()]
	
	    [Required(AllowEmptyStrings=false, ErrorMessageResourceName="VAL_SELLSTARTDATE_REQUIRED", ErrorMessageResourceType=typeof(ProductResources))]
		
	[RelationFilterable()]
	[DateTime(true, false, null)]	
	[LocalizedDisplayName("SELLSTARTDATE", NameResourceType=typeof(ProductResources))]
	public DateTime   SellStartDate { get; set; }
	public string SellStartDateText {
        get {
            if (SellStartDate != null)
			
                return ((DateTime)SellStartDate).ToShortDateString();
            else
                return String.Empty;
        }
				set{
				this.SellStartDate = Convert.ToDateTime(value);
    }
		}
		
		
	
[Exportable()]
		
	[RelationFilterable()]
	[DateTime(true, false, null)]	
	[LocalizedDisplayName("SELLENDDATE", NameResourceType=typeof(ProductResources))]
	public DateTime  ? SellEndDate { get; set; }
	public string SellEndDateText {
        get {
            if (SellEndDate != null)
			
                return ((DateTime)SellEndDate).ToShortDateString();
            else
                return String.Empty;
        }
				set{
				this.SellEndDate = Convert.ToDateTime(value);
    }
		}
		
		
	
[Exportable()]
		
	[RelationFilterable()]
	[DateTime(true, false, null)]	
	[LocalizedDisplayName("DISCONTINUEDDATE", NameResourceType=typeof(ProductResources))]
	public DateTime  ? DiscontinuedDate { get; set; }
	public string DiscontinuedDateText {
        get {
            if (DiscontinuedDate != null)
			
                return ((DateTime)DiscontinuedDate).ToShortDateString();
            else
                return String.Empty;
        }
				set{
				this.DiscontinuedDate = Convert.ToDateTime(value);
    }
		}
		
		
	
[Exportable()]
		
	[RelationFilterable()]
 
	[DataType("File")]
	[LocalizedDisplayName("THUMBNAILPHOTO", NameResourceType=typeof(ProductResources))]
	public Byte[]   ThumbNailPhoto { get; set; }
		
		
	
[Exportable()]
		
	[RelationFilterable()]
	[LocalizedDisplayName("THUMBNAILPHOTOFILENAME", NameResourceType=typeof(ProductResources))]
	public String   ThumbnailPhotoFileName { get; set; }
		
		
	
[Exportable()]
		
	[RelationFilterable()]
	[SystemProperty()]
	[LocalizedDisplayName("ROWGUID", NameResourceType=typeof(ProductResources))]
	public Guid   rowguid { get; set; }
		
		
	
[Exportable()]
	
	    [Required(AllowEmptyStrings=false, ErrorMessageResourceName="VAL_MODIFIEDDATE_REQUIRED", ErrorMessageResourceType=typeof(ProductResources))]
		
	[RelationFilterable()]
	[DateTime(true, false, null)]	
	[LocalizedDisplayName("MODIFIEDDATE", NameResourceType=typeof(ProductResources))]
	public DateTime   ModifiedDate { get; set; }
	public string ModifiedDateText {
        get {
            if (ModifiedDate != null)
			
                return ((DateTime)ModifiedDate).ToShortDateString();
            else
                return String.Empty;
        }
				set{
				this.ModifiedDate = Convert.ToDateTime(value);
    }
		}
		
		
	
[Exportable()]
		
	[RelationFilterable(DataClassProvider = typeof(Controllers.ProductCategoriesController), GetByKeyMethod="GetByKey", GetAllMethod = "GetAll", DataPropertyText = "Name", DataPropertyValue = "ProductCategoryID", FiltrablePropertyPathName="ProductCategory.ProductCategoryID")]	

	[LocalizedDisplayName("PRODUCTCATEGORY", NameResourceType=typeof(ProductResources))]
	public Int32  ? FkProductCategory { get; set; }
		[LocalizedDisplayName("PRODUCTCATEGORY", NameResourceType=typeof(ProductResources))]
	[Exportable()]
	public string  FkProductCategoryText { get; set; }
    public string FKProductCategorySafeKey { get; set; }

	
		
	
[Exportable()]
		
	[RelationFilterable(DataClassProvider = typeof(Controllers.ProductModelsController), GetByKeyMethod="GetByKey", GetAllMethod = "GetAll", DataPropertyText = "Name", DataPropertyValue = "ProductModelID", FiltrablePropertyPathName="ProductModel.ProductModelID")]	

	[LocalizedDisplayName("PRODUCTMODEL", NameResourceType=typeof(ProductResources))]
	public Int32  ? FkProductModel { get; set; }
		[LocalizedDisplayName("PRODUCTMODEL", NameResourceType=typeof(ProductResources))]
	[Exportable()]
	public string  FkProductModelText { get; set; }
    public string FKProductModelSafeKey { get; set; }

	
		
		
		[LocalizedDisplayName("SALESORDERDETAILS", NameResourceType=typeof(ProductResources))]
		[RelationFilterable(IsNavigationPropertyMany=true, FiltrablePropertyPathName="SalesOrderDetails.Count()", ModelPartialType="SalesOrderDetails.SalesOrderDetail")]
        public List<SalesOrderDetails.SalesOrderDetailModel> SalesOrderDetails { get; set; }			
	
	public override string SafeKey
   	{
		get
        {
			if(this.ProductID != null)
				return SFSdotNet.Framework.Entities.Utils.GetKey(this ,"ProductID").Replace("/","-");
			else
				return String.Empty;
		}
    }		
		public void Bind(ProductModel model){
            
		this.ProductID = model.ProductID;
		this.Name = model.Name;
		this.ProductNumber = model.ProductNumber;
		this.Color = model.Color;
		this.StandardCost = model.StandardCost;
		this.ListPrice = model.ListPrice;
		this.Size = model.Size;
		this.Weight = model.Weight;
		this.SellStartDate = model.SellStartDate;
		this.SellEndDate = model.SellEndDate;
		this.DiscontinuedDate = model.DiscontinuedDate;
		this.ThumbNailPhoto = model.ThumbNailPhoto;
		this.ThumbnailPhotoFileName = model.ThumbnailPhotoFileName;
		this.rowguid = model.rowguid;
		this.ModifiedDate = model.ModifiedDate;
        }

        public BusinessObjects.Product GetBusinessObject()
        {
            BusinessObjects.Product result = new BusinessObjects.Product();
	if (this.ProductID != null )
				result.ProductID = (Int32)this.ProductID;
				
	if (this.Name != null )
				result.Name = (String)this.Name.Trim().Replace("\t", String.Empty);
				
	if (this.ProductNumber != null )
				result.ProductNumber = (String)this.ProductNumber.Trim().Replace("\t", String.Empty);
				
	if (this.Color != null )
				result.Color = (String)this.Color.Trim().Replace("\t", String.Empty);
				
	if (this.StandardCost != null )
				result.StandardCost = (Decimal)this.StandardCost;
				
	if (this.ListPrice != null )
				result.ListPrice = (Decimal)this.ListPrice;
				
	if (this.Size != null )
				result.Size = (String)this.Size.Trim().Replace("\t", String.Empty);
				
	if (this.Weight != null )
				result.Weight = (Decimal)this.Weight;
				
				result.SellStartDate = (DateTime)this.SellStartDate;		
				
				if(this.SellEndDate != null)
					if (this.SellEndDate != null)
				result.SellEndDate = (DateTime)this.SellEndDate;		
				
				if(this.DiscontinuedDate != null)
					if (this.DiscontinuedDate != null)
				result.DiscontinuedDate = (DateTime)this.DiscontinuedDate;		
				
				if(this.ThumbNailPhoto != null)
					result.ThumbNailPhoto = (Byte[])this.ThumbNailPhoto;
			
				
	if (this.ThumbnailPhotoFileName != null )
				result.ThumbnailPhotoFileName = (String)this.ThumbnailPhotoFileName.Trim().Replace("\t", String.Empty);
				
	if (this.rowguid != null )
				result.rowguid = (Guid)this.rowguid;
				
				result.ModifiedDate = (DateTime)this.ModifiedDate;		
				
			
			if(this.FkProductCategory != null )
	result.ProductCategory = new BusinessObjects.ProductCategory() { ProductCategoryID= (Int32)this.FkProductCategory };
				
			
			if(this.FkProductModel != null )
	result.ProductModel = new BusinessObjects.ProductModel() { ProductModelID= (Int32)this.FkProductModel };
				



            return result;
        }
        public void Bind(BusinessObjects.Product businessObject)
        {
            
			this.ProductID = businessObject.ProductID;
				
			this.Name = businessObject.Name != null ? businessObject.Name.Trim().Replace("\t", String.Empty) : "";
				
			this.ProductNumber = businessObject.ProductNumber != null ? businessObject.ProductNumber.Trim().Replace("\t", String.Empty) : "";
				
				
	if (businessObject.Color != null )
				this.Color = (String)businessObject.Color;
			this.StandardCost = businessObject.StandardCost;
				
			this.ListPrice = businessObject.ListPrice;
				
				
	if (businessObject.Size != null )
				this.Size = (String)businessObject.Size;
				
	if (businessObject.Weight != null )
				this.Weight = (Decimal)businessObject.Weight;
				this.SellStartDate = (DateTime)businessObject.SellStartDate;
				if (businessObject.SellEndDate != null )
				this.SellEndDate = (DateTime)businessObject.SellEndDate;
				if (businessObject.DiscontinuedDate != null )
				this.DiscontinuedDate = (DateTime)businessObject.DiscontinuedDate;
			if (businessObject.ThumbNailPhoto != null )
				this.ThumbNailPhoto = businessObject.ThumbNailPhoto;			
				
	if (businessObject.ThumbnailPhotoFileName != null )
				this.ThumbnailPhotoFileName = (String)businessObject.ThumbnailPhotoFileName;
			this.rowguid = businessObject.rowguid;
				
				this.ModifiedDate = (DateTime)businessObject.ModifiedDate;
	        if (businessObject.ProductCategory != null){
	                	this.FkProductCategoryText = businessObject.ProductCategory.Name.Trim().Replace("\t", String.Empty); 
										
										
				this.FkProductCategory = businessObject.ProductCategory.ProductCategoryID;
                this.FKProductCategorySafeKey  = SFSdotNet.Framework.Entities.Utils.GetKey(businessObject.ProductCategory,"ProductCategoryID").Replace("/","-");

			}
	        if (businessObject.ProductModel != null){
	                	this.FkProductModelText = businessObject.ProductModel.Name.Trim().Replace("\t", String.Empty); 
										
										
				this.FkProductModel = businessObject.ProductModel.ProductModelID;
                this.FKProductModelSafeKey  = SFSdotNet.Framework.Entities.Utils.GetKey(businessObject.ProductModel,"ProductModelID").Replace("/","-");

			}
           
        }
	}
}
